package com.yang.frost.blueberry.util;

import org.fusesource.jansi.Ansi;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;

/**
 * @author 10296
 * @date 2021/1/13
 * @Description:
 */
public class AnsiUtil {


    private static boolean enableAnsi;

    static {
        Boolean value = false;
        try {
            value = true;
//            Environment environment = SpringContextUtil.getBean(Environment.class);
//            value = environment.getProperty("blueberry.enable-ansi", boolean.class);
            value = value == null ? false : value;
        } catch (Exception e) {
            e.printStackTrace();
        }
        enableAnsi = value;
    }

    public static String getAnsi(Ansi.Color color, String text) {

        if (enableAnsi) {
            return Ansi.ansi().eraseScreen().fg(color).a(text).reset().toString();
        }
        return text;
    }

    public static String getAnsi(Ansi.Color color, String text, boolean flag) {
        if (flag) {
            return Ansi.ansi().eraseScreen().fg(color).a(text).reset().toString();
        }
        return text;
    }

}



